package com.yuhan.common.base;

import com.yuhan.common.utils.R;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: duff
 * @Date: 2019/6/18 14:08
 */
public class BaseController<D extends BaseService, T extends BaseEntity> {

    @Autowired
    private D baseService;

    @ApiOperation("根据id查询")
    @GetMapping("/list/{id}")
    public R getOne(@PathVariable String id) {
        return baseService.findById(id);
    }

    @ApiOperation("根据id删除")
    @PostMapping("/del/{id}")
    public R delOne(@PathVariable String id) {
        return baseService.deleteById(id);
    }

    @ApiOperation("新增或者更新")
    @PostMapping("/save")
    public R saveOne(@RequestBody @Validated T baseEntity) {
        return baseService.saveOrUpdate(baseEntity);
    }

    @ApiOperation("批量删除")
    @PostMapping("/del/batch")
    public R delBatch(@RequestParam List<String> ids) {
        return baseService.deleteAll(ids);
    }
}